<?php
/**
 * Created by PhpStorm.
 * User: stupboy
 * Date: 2018/4/4
 * Time: 15:50
 * Mail:87658989@qq.com
 */

namespace app\base\logic;


use app\base\service\Dayu;
use app\base\service\Yimei;
use app\base\service\Redis;
class Sms
{
    public function send($phone,$msg){
        (new Yimei())->send($phone,$msg);
    }

    /**
     * 短信加入队列
     * @param string $mobile
     * @param array $data
     * @param string $templateCode
     * @param int $ser
     */
    public function addToList($mobile='',$data = [],$templateCode = 'SMS_130911261',$ser = 1){
        // $ser = 2;
        // TODO 读取配置短信服务商
        $arr = [
            'mobile'=>$mobile,
            'data'  =>$data,
            'code'  =>$templateCode,
            'server'=>$ser
        ];
        Redis::getInstance()->push('send_sms_list',serialize($arr));
    }

    public function sendTemplate($mobile,$data,$template,$ser=2){
        // 旧短信
        if($ser == 1){
            return (new Yimei())->sendByTemplate($mobile,$data,$template);
        }
        // 阿里云短信
        if($ser == 2){
            return (new Dayu())->sendMsg($mobile,$data,$template);
        }
    }
}